local hx__jiaohui = fk.CreateSkill{
  name = "hx__jiaohui",
  tags = { Skill.Switch, Skill.Compulsory },
}


hx__jiaohui:addEffect(fk.RoundStart, {
  anim_type = "switch",
  can_trigger = function(self, event, target, player, data)
    if player:getSwitchSkillState(hx__jiaohui.name, false) == fk.SwitchYang then
      return player:hasSkill(hx__jiaohui.name)
    else
      local tos = table.filter(player.room:getOtherPlayers(player), function(p) return p.kingdom ~= "wu" end)
      return player:hasSkill(hx__jiaohui.name) and #tos > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    if player:getSwitchSkillState(hx__jiaohui.name, true) == fk.SwitchYang then
      player:gainAnExtraTurn()
    else
      local tos = table.filter(player.room:getOtherPlayers(player), function(p) return p.kingdom ~= "wu" end)
      if #tos == 0 then return false end
      local to = table.random(tos)
      player.room:swapSeat(player, to)
      player.room:sendLog{type = "#hx__jiaohui", from = player.id, to = {to.id}}
    end
  end,
})


return hx__jiaohui
